import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;



public class DS_JSON implements IDS {

	private String fName = "";
	
	public DS_JSON( String fName )
	{
		this.fName = fName;
	}

	@Override
	public void Save(List<Person> pp) 
	{
		try 
		{
			FileWriter file = new FileWriter(fName);
			JSONObject obj = new JSONObject();
			JSONArray ar = new JSONArray();
			//ar.addAll(pp);
			//obj.put("Persons", ar);
			obj.put("Persons", new Person(10,"ddd", "zzz", 25) );
			obj.writeJSONString(file);
			file.close();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}

	@Override
	public List<Person> Load() 
	{		
		try 
		{	
			JSONParser parser = new JSONParser();
			Object obj = parser.parse(new FileReader(fName));
	 
			JSONObject jsonObject = (JSONObject) obj;
	 
			//List<Person> pp = (String) jsonObject.get("ListOfPersons");
			System.out.println( obj.getClass().getSimpleName());
	 

	 
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
	}

}
